package com.qxzn.module.home.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lmc.entity.Skills;
import com.lmc.util.GlideUtil;
import com.qxzn.module.home.R;

import java.util.List;

public class WidgetItemAdapter extends RecyclerView.Adapter<WidgetItemAdapter.ViewHolder> {
    private Activity activity;
    List<Skills.SkillsBen> dataList;

    public WidgetItemAdapter(Activity activity, List<Skills.SkillsBen> robotDataList) {
        this.activity = activity;
        dataList = robotDataList;
    }

    @NonNull
    @Override
    public WidgetItemAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(activity).inflate(R.layout.lmc_home_select_item_list_item, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.underLine.setVisibility(position == dataList.size() - 1 ? View.INVISIBLE : View.VISIBLE);
        Skills.SkillsBen ben = dataList.get(position);
        GlideUtil.setImg(activity, holder.icon, ben.getIcon());
        holder.name.setText(ben.getName());
        try {
            String[] split = ben.getVoice().split(",");
            holder.sub1.setText(split[0]);
            holder.sub2.setText(split[1]);
        }catch (Exception e){

        }
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView icon;
        TextView name;
        TextView sub1;
        TextView sub2;
        View underLine;

        public ViewHolder(View itemView) {
            super(itemView);
            icon = itemView.findViewById(R.id.thumbnail);
            name = itemView.findViewById(R.id.name);
            sub1 = itemView.findViewById(R.id.text1);
            sub2 = itemView.findViewById(R.id.text2);
            underLine = itemView.findViewById(R.id.line);
        }
    }
}
